package com.example.whm;

import org.holoeverywhere.LayoutInflater;
import org.holoeverywhere.app.Fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.androidquery.AQuery;
import com.androidquery.util.AQUtility;
import com.viewpagerindicator.TabPageIndicator;



public  class TwoFragment extends Fragment {

	private AQuery aq;
	private AQuery aq2;
	
	private String topic;
	private ViewPager pager;
	private PageAdapter adapter;
	TabPageIndicator indicator;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.two_layout, container, false);  
		pager =(ViewPager) view.findViewById(R.id.two_layout_pager);
	    indicator = (TabPageIndicator)view.findViewById(R.id.two_layout_indicator);
	    
		
		return view;
	}

	
	
	
	
	
	
	
	
	

    @Override
	public void onActivityCreated(Bundle savedInstanceState) {
    	super.onActivityCreated(savedInstanceState);
    	adapter=new PageAdapter(getChildFragmentManager());
	    pager.setAdapter(adapter);
	    pager.setOffscreenPageLimit(1);
	    indicator.setViewPager(pager);
	  
	}











	//
    public static String[] topics = {"zaodian","xiawucha", "xianguo", "shaokao","xiaochi", "tianping"};
	
	public  class PageAdapter extends FragmentStatePagerAdapter{


		public PageAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int pos) {
			
			AQUtility.debug("primary", topics[pos]);
			//TwoFragmentItem f=new TwoFragmentItem();
			Bundle args = new Bundle();
			
			args.putString("topic", topics[pos]);
			args.putInt("type", pos+1);
			//System.out.println("------------------------1");
			TwoFragmentItem fragment = (TwoFragmentItem) Fragment.instantiate( TwoFragmentItem.class, args);
			
			return fragment;
		}

		@Override
		public int getCount() {
			return topics.length;
		}
		


		@Override
        public CharSequence getPageTitle (int pos) {
            return topics[pos];
        }
		
		@Override
		public void setPrimaryItem(ViewGroup container, int position, Object object){
			
			AQUtility.debug("primary", topics[position]);
	         
			System.out.println("--------setPrimaryItem------------");
			/*if (position!=0) {
				
				TwoFragmentItem fragment = (TwoFragmentItem)object;
				fragment.init();
			}*/
			
		}
		
		@Override
		public void destroyItem(ViewGroup container, int position, Object object){
			AQUtility.debug("destroyItem", topics[position]);
		}
		
		
	}

 
}
